Conditional Comment
   HOME

TheInfoList



OR:

Conditional comments are conditional statements interpreted by
Microsoft Microsoft Corporation is an American multinational technology corporation producing computer software, consumer electronics, personal computers, and related services headquartered at the Microsoft Redmond campus located in Redmond, Washing ...
Internet Explorer Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical user interface, graphical web browsers developed by Microsoft which was used in the Microsoft Wind ...
versions 5 through 9 in
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScri ...
source code. They can be used to provide and hide code to and from these versions of Internet Explorer. Conditional comments are not supported in
Internet Explorer 10 Internet Explorer 10 (IE10) is the tenth, and by now, discontinued, version of the Internet Explorer web browser and the successor to Internet Explorer 9, released by Microsoft on September 4, 2012, shortly after the completion of Windows Serv ...
and 11. Conditional comments in HTML first appeared in Microsoft's Internet Explorer 5 browser, although support has now been deprecated. In Internet Explorer 10, HTML conditional comments are not supported when the page is in standards mode (document mode 10).
JScript JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer 11 and older. JScript is implemented as an Active Scripting engine. This means that it can be "plugged in" to OLE Automation applicati ...
conditional comments were introduced in
Internet Explorer 4 Microsoft Internet Explorer 4 (IE4) is a graphical web browser that Microsoft unveiled in Spring of 1997, and released in September 1997, primarily for Microsoft Windows, but also with versions available for the classic Mac OS, Solaris, and H ...
, and they continued to be supported in Internet Explorer 10, in standards mode or compatibility mode.


Examples

Here is a simple example that demonstrates how conditional comments work.


Syntax

There are two types of "conditional comments": ''downlevel revealed'', and ''downlevel hidden''. The basic syntax of each type of comment is shown in the following table. The first comment shown is the basic HTML Comment, which is included for the purpose of comparison and to illustrate the different syntax used by each type of conditional comment. The ''HTML'' shown inside the syntax block in each of the conditional comments denotes any block of HTML content, including script. Both types of conditional comment use a conditional ''expression'' to indicate whether the content inside the comment block should be parsed or ignored. The conditional expression is formed from a combination of feature, operator, and/or value, depending on the feature. The following table shows the supported features and describes the values each feature supports. The following table describes the operators that can be used to create conditional expressions.


Downlevel-hidden conditional comment

Below are two examples of a "downlevel hidden" conditional comment: or The directive in the first example will let IE 8 read the specified CSS file, while IE 7 or older IE versions will ignore it. Browsers other than IE will also ignore it because it looks like a standard HTML comment. The tag in the second example will let IE versions 5.0 through 7 read the internal CSS style. With different uses of this tag you can also single out IE 6, IE 5, or versions of IE that are newer (greater) or older (less) than a specified version.


Downlevel-revealed conditional comment

Below is an example of a "downlevel revealed" conditional 'comment', which is ''not an (X)HTML'' comment at all, despite the misleading name, using the default Microsoft syntax: f !IE ndif This example shows content that should be exposed only to non-IE browsers, as the condition evaluates to "false" on IE (and hence the content is ignored), while the tags themselves are unrecognized (and hence ignored) on non-IE browsers. This is not valid HTML or XHTML. Microsoft acknowledges this syntax is not standardized markup, intending these tags to be overlooked by other browsers and expose the content in the middle. In order to ensure compliance with W3C standards, some web developers use an alternative technique for downlevel-revealed conditional comments: While somewhat confusing in structure, this specific syntax is valid (X)HTML and is useful for conditional sections intended specifically for non-IE browsers; if the condition evaluates to ''true'' (for example, if writing code meant to display on non-IE browsers ''and'' on some versions of IE), IE will then display the "-->" present before the HTML content. This problem is easily solved by prepending "" as follows: This code displays on non-IE browsers and on IE 7 or higher. is unrecognized and therefore ignored.


Conditional comments in JScript

Starting with Internet Explorer 4, there exists a similar proprietary mechanism for adding conditional comments within
JScript JScript is Microsoft's legacy dialect of the ECMAScript standard that is used in Microsoft's Internet Explorer 11 and older. JScript is implemented as an Active Scripting engine. This means that it can be "plugged in" to OLE Automation applicati ...
, known as conditional compilation. Code examples: There were also several predefined variables, though these cannot be relied on any longer as Microsoft altered the JScript engine of IE6 with XP SP3 and it now reports as: @_jscript_version

5.7
As a result, a possible way to detect Internet Explorer version using conditional compilation can be seen below: However, conditional compilation is no longer supported in
Internet Explorer 11 Internet Explorer 11 (IE11) is the eleventh, final, and now deprecated version of the Internet Explorer web browser. It was initially included in the release of Windows 8.1, Windows RT 8.1 and Windows Server 2012 R2 on October 17, 2013, and was ...
Standards mode.https://msdn.microsoft.com/library/8ka90k2e(v=vs.94).aspx @cc_on Statement (JavaScript)


See also

* CSS filter


External links


Conditional Comments in HTML


References

{{reflist HTML Cascading Style Sheets Internet Explorer